<template>
  <transition appear name="article">
    <div class="main">
      <div class="article-container">
        <div class="index-banner">
          <div class="banner-box">
            <Banner ></Banner>
          </div>
        </div>
        <div class="article_box">
          <div class="posts" v-for="(item, index) in articles" :key="index">
            <div class="post-cover">
              <img
                v-show="coverIsShow"
                src="../../../assets/image/default-cover.jpeg"
                alt="封面"
              />
              <div class="hover-time">
                <i class="iconfont icon-time"></i>
                <span>{{ item.create_time }}</span>
              </div>
            </div>
            <div class="right-article-detail">
              <p class="post-title">
                {{ item.title }}
              </p>
              <p class="post-body">
                {{ item.body_md | ellipsis(60) }}
              </p>
              <div class="post-bottom">
                <div class="tags">
                  <span
                    v-for="(sitem, sindex) in item.tags"
                    :key="sindex"
                    class="tag"
                    >{{ sitem }}</span
                  >
                </div>

                <span class="post-readAll" @click="goDetail(item._id)"
                  >阅读全文</span
                >
                <div class="post-time">
                  <i class="iconfont icon-time"></i>
                  <span>{{ item.create_time }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <Pagination :options="options" @currentChange="currentChange"></Pagination>
    </div>
  </transition>
</template>

<script>
import Banner from "./Banner.vue";
import Pagination from "./Pagination.vue";

export default {
  name: "articlepart",
  data() {
    return {
      coverIsShow: true,
      options: {
        total: 0, //全部总数
        pageSize: 4, //每页几条数据
        currentPage: 1, //当前页
      },
    };
  },
  components: {
    Banner,
    Pagination,
  },
  props: {
    articles: Array,
    screenWidth: Number,
    artTotal: Number,
  },
  methods: {
    goDetail(data) {
      this.$router.push(`/article/${data}`);
    },
    currentChange(current) {
      this.options.current = current;
      this.$emit("getArticle", this.options);
    },
  },
  filters: {
    ellipsis(value, limit) {
      if (!value) return "";
      if (value.length > limit) {
        return value.slice(0, limit) + "...";
      }
      return value;
    },
  },
  watch: {
    screenWidth: {
      immediate: true,
      handler: function (val, oldVal) {
        if (val < 650) {
          this.coverIsShow = false;
        } else {
          this.coverIsShow = true;
        }
      },
    },
  },
  created() {
    this.$emit("getArticle", this.options);
  },
};
</script>

<style scoped lang="scss">

.main {
  display: flex;
  flex-wrap: wrap;
  width: 90%;
  padding: 15px;
  margin: 0 auto;
  .article-container {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    padding: 15px 15px 25px;
    box-shadow: 0 0 18px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    transition: all 0.5s;
    .index-banner {
      width: 100%;
      .banner-box {
        width: 100%;
      }
    }
    .article_box {
      width: 100%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      transition: all 0.5s;
      .posts {
        width: 100%;
        height: 180px;
        display: flex;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
        padding: 10px 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.3);
        transition: all 0.5s;
        overflow: hidden;
        box-sizing: content-box;

        .post-cover {
          width: 240px;
          height: 180px;
          overflow: hidden;
          position: relative;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          .hover-time {
            position: absolute;
            right: -100%;
            top: 10px;
            background-color: brown;
            color: orange;
            font-size: 13px;
            transition: all 0.5s ease-in-out;
            padding: 5px;
            user-select: none;
            border-radius: 10px 0 0 10px;
            i {
              font-size: 13px;
            }
          }
        }
        .right-article-detail {
          min-width: 0;
          flex: 1;
          margin-left: 22px;
          font-family: Optima-Regular, Optima, -apple-system, system-ui,
            Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif,
            BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB,
            Microsoft YaHei, Arial;
          .post-title {
            font-size: 22px;
            font-weight: 500;
          }
          .post-body {
            width: 100%;
            font-size: 14px;
            font-weight: 200;
            line-height: 22px;
            margin: 12px 0;
          }
          .post-bottom {
            width: 100%;
            text-align: center;
            display: flex;
            justify-content: left;
            flex-wrap: wrap;
            padding: 0 0 20px;
            position: relative;

            .tags {
              width: 70%;
              height: 10px;
              display: flex;
              justify-content: left;
              line-height: 10px;

              .tag {
                height: 100%;
                color: #ddd;
                margin: 5px;
                font-size: 12px;
                padding: 5px;
                cursor: pointer;
                border-radius: 4px;
              }
              .tag:nth-child(1) {
                background-color: skyblue;
                color: #fff;
              }
              .tag:nth-child(2) {
                background-color: rgba(8, 164, 8, 0.868);
                color: #fff;
              }
              .tag:nth-child(3) {
                background-color: rosybrown;
                color: #fff;
              }
            }
            .post-time {
              position: absolute;
              left: 0;
              bottom: 0;
              font-size: 12px;
              font-weight: 400;
              i {
                font-size: 14px;
              }
              span {
                font-weight: 600;
                padding-bottom: 5px;
              }
            }
            .post-readAll {
              width: 30%;
              flex: 1;
              margin-right: 0;
              font-size: 16px;
              font-weight: 500;
              color: #000;
              transition: all 0.5s;
              // float: right;
              line-height: 30px;
            }
            .post-readAll:hover {
              color: skyblue;
              cursor: pointer;
            }
          }
        }
      }
      .posts:hover {
        img {
          transform: scale(1.115);
          transition: all 0.5s;
        }
      }
    }
  }
}

.article-enter-active,
.article-leave-active {
  transition: all 0.7s ease-in-out;
}

.article-enter,
.article-leave-to {
  transform: scale(0.8);
  opacity: 0.2;
  transform-origin: top left;
}
.article-enter-to,
.article-leave {
  transform: scale(1);
  transform-origin: top left;
  opacity: 1;
}
@media screen and (max-width: 650px) {
  .main {
    width: 100%;
    margin: 0 auto;
    padding: 5px 0;
    .article-container {
      padding: 5px;
      .article_box {
        width: 100%;
        margin: 0 auto;
        padding-bottom: 10px;

        .posts {
          height: 160px;
          .post-cover {
            display: none;
          }

          .right-article-detail {
            min-width: 0;
            flex: 1;
            margin-left: 0;
            padding: 10px;
            font-family: Optima-Regular, Optima, -apple-system, system-ui,
              Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif,
              BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB,
              Microsoft YaHei, Arial;

            .post-title {
              font-size: 22px;
              font-weight: 500;
            }

            .post-body {
              font-size: 14px;
              font-weight: 200;
              line-height: 22px;
              margin: 0;
            }

            .post-bottom {
              width: 100%;
              text-align: center;
              display: flex;
              justify-content: space-between;

              .post-time {
                font-size: 12px;
                font-weight: 400;
                line-height: 16px;
              }

              .post-readAll {
                font-size: 18px;
                font-weight: 500;
                transition: all 0.5s;
              }

              .post-readAll:hover {
                color: skyblue;
                cursor: pointer;
              }
            }
          }
        }
      }
    }
  }
}

// 最小宽度设置为1100
@media screen and (min-width: 650px) and (max-width: 1100px) {
  .main {
    width: 90%;
    margin: 0 auto;
  }
}
</style>